package doctor;

import java.text.Collator;
import java.util.Locale;

/**
 * @author caiwl
 * @date 2020/5/25 10:13
 */
public class Doctor implements Comparable<Doctor> {
    /** 剩余号源 */
    private int leftSource;
    /** 职称 */
    private String title;
    /** 职称等级 */
    private int titleLevel;
    /** 姓名 */
    private String name;

    public Doctor(int leftSource, String title, int titleLevel, String name) {
        this.leftSource = leftSource;
        this.title = title;
        this.titleLevel = titleLevel;
        this.name = name;
    }

    public int getLeftSource() {
        return leftSource;
    }

    public void setLeftSource(int leftSource) {
        this.leftSource = leftSource;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public int getTitleLevel() {
        return titleLevel;
    }

    public void setTitleLevel(int titleLevel) {
        this.titleLevel = titleLevel;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return String.format("Doctor{leftSource=%s, title=%s, name=%s}", leftSource, title, name);
    }


    @Override
    public int compareTo(Doctor o) {
        // 都有号源
        if (o.getLeftSource() > 0 && this.getLeftSource() > 0) {
            // 检查职称
            int compare = o.getTitleLevel() - this.getTitleLevel();
            if (compare != 0) {
                return compare;
            }
            // 同职称，按号源多少排序
            compare = o.getLeftSource() - this.getLeftSource();
            if (compare != 0) {
                return compare;
            }
            // 同职称，同号源，按首字母排序
            return Collator.getInstance(Locale.CHINA).compare(this.getName(), o.getName());
        }
        // 都无号源
        else if (o.getLeftSource() == 0 && this.getLeftSource() == 0) {
            // 检查职称
            int compare = o.getTitleLevel() - this.getTitleLevel();
            if (compare != 0) {
                return compare;
            }
            // 同职称，按首字母排序
            return Collator.getInstance(Locale.CHINA).compare(o.getName(), this.getName());
        }
        // 一个有号源，一个无号源
        else {
            return (o.getLeftSource() - this.getLeftSource());
        }
    }
}
